#include <nice2d/util.h>
#include <nice2d/anchor.h>

class AnchorData
{
public:
    sf::Vector2f offset;
    HMode hMode = HMode_Center;
    VMode vMode = VMode_Center;
    float angle = 0.0f;
};

Anchor::Anchor():
    data(new AnchorData)
{
}

Anchor::~Anchor()
{
}

void Anchor::setXOffset(float offset)
{
    if(!isEqual<float>(offset,data->offset.x,1e-5))
    {
        data->offset.x = offset;
        updateAnchor();
    }
}

void Anchor::setYOffset(float offset)
{
    if(!isEqual<float>(offset,data->offset.y,1e-5))
    {
        data->offset.y = offset;
        updateAnchor();
    }
}

sf::Vector2f Anchor::getOffset() const
{
    return data->offset;
}

void Anchor::setHAlignment(HMode mode)
{
    if(data->hMode != mode)
    {
        data->hMode = mode;
        updateAnchor();
    }
}

HMode Anchor::getHAligment() const
{
    return data->hMode;
}

void Anchor::setVAlignment(VMode mode)
{
    if(data->vMode != mode)
    {
        data->vMode = mode;
        updateAnchor();
    }
}

VMode Anchor::getVAlignment() const
{
    return data->vMode;
}

void Anchor::setRotate(float angle)
{
    if(!isEqual<float>(angle,data->angle,1e-5))
    {
        data->angle = angle;
        updateAnchor();
    }
}

float Anchor::getRotate() const
{
    return data->angle;
}
